package com.douyin.controller;

import com.douyin.entity.Video;
import com.douyin.mapper.VideoMapper;
import com.douyin.service.VideoService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import java.util.List;

// controller 依赖 service
@Data
@Controller  //  component 是通过注解，用来表明身份要被扫描成组件，bean被IOC容器接管
// component 是一个通用注解，用来声明，这个类要被spring接管成bean ,它有三个衍生（别名）注解 Controller Service  @Repository
public class VideoController { //videoController
    @Autowired
    private VideoService videoService;  // 将videoService对象注入进来,这样就可以使用了


    public List<Video> selectAllVideos() {
        return videoService.selectAllVideos();
    }


    public Video selectVideoById(int id) {
        return videoService.selectVideoById(id);
    }


    public String deleteVideoById(int id) {
        return videoService.deleteVideoById(id) ? "删除成功" : "删除失败";
    }


    public String insertOneVideo(Video video) {
        return videoService.insertOneVideo(video) ? "添加成功" : "添加失败";
    }


    public String updateOneVideo(Video video) {
        return videoService.updateOneVideo(video) ? "修改成功" : "修改失败";
    }
}
